var combinationSum4 = function(nums, target) {
  const len = nums.length;
  const dp = new Array(target + 1).fill(0);
  dp[0] = 1;


    // 排列数 先背包 再物品 使得物品1、3和3、1都能出现
  for (let i = 1; i <= target; i++) {
    for (let j = 0; j < len; j++) {
      if (nums[j] <= i) {
        dp[i] += dp[i - nums[j]];
      }
    }
  }

  return dp[target];

};

const nums = [1,2,3], target = 4;
console.log(combinationSum4(nums, target));